import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SettingPage extends StatefulWidget {
  const SettingPage({super.key});

  @override
  State<SettingPage> createState() => _SettingPageState();
}

class _SettingPageState extends State<SettingPage>
    with TickerProviderStateMixin {
//实现这个动画你首先需要继承TickerProviderStateMixin

//然后定义一个AnimationController控制器，并且需要初始化，所以你这个组件必须是动态组件

//然后就是按钮必须是动画按钮，把控制器放进去，然后操控forward和reverse

  bool isChanged = false;
  late AnimationController controller;

  @override
  void initState() {
    super.initState();
    controller =
        AnimationController(vsync: this, duration: const Duration(seconds: 1));
  }

  @override
  void dispose() {
    //路由销毁时需要释放动画资源
    controller.dispose();
    // TODO: implement dispose
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    void trigger() {
      setState(() {
        isChanged = !isChanged;
        isChanged ? controller.forward() : controller.reverse();
      });
    }

    return Center(
      child: Column(
        children: [
          const Text("设置页面"),
          ElevatedButton(
              onPressed: () {
                Navigator.of(context).pushNamed('/dialog');
              },
              child: const Text("dialog演示")),
          RichText(
              text: const TextSpan(
                  style: TextStyle(fontSize: 20, color: Colors.black),
                  children: [
                TextSpan(text: '今天消费：'),
                TextSpan(
                    text: '100万',
                    style: TextStyle(
                        fontWeight: FontWeight.bold, color: Colors.blue))
              ])),
          const Padding(
            padding: EdgeInsets.all(20),
            child: Text('试试点击下面的图标'),
          ),
          IconButton(
              onPressed: trigger,
              icon: AnimatedIcon(
                icon: AnimatedIcons.menu_home,
                color: Colors.orangeAccent,
                progress: controller,
              )),
          ElevatedButton(
              onPressed: () {
                Get.toNamed('/indexstack');
              },
              child: const Text("测试多个webview后台运行"))
        ],
      ),
    );
  }
}
